package panel.sunTime
{
	import assists.HtmlText;
	import assists.Scale9Grid;
	import assists.TextFieldUtils;
	import assists.resource.ResourceLoader;
	
	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.text.TextField;
	
	public class SunTimeItem extends Sprite
	{
		private var _stage:Stage;
		private var _loader:ResourceLoader;
		
		private var _risesTxt:TextField = new TextField();
		private var _risesTitleTxt:TextField = new TextField();
		private var _sunSetTxt:TextField = new TextField();
		private var _sunSetTitleTxt:TextField = new TextField();
		private var _backGround:Bitmap;
		public function SunTimeItem(stage:Stage,loader:ResourceLoader,days:int)
		{
			_stage = stage;
			_loader = loader;
		
			var dayStr:String = "";
			if(days == 0)
			{
				dayStr = "今天  ";
			}else if(days == 1)
			{
				dayStr = "明天  ";
			}else if(days == 2)
			{
				dayStr = "后天  ";
			}
			
			_risesTitleTxt.mouseEnabled = false;
			_risesTitleTxt.autoSize = "left";
			TextFieldUtils.setHtmlText(_risesTitleTxt,HtmlText.format(dayStr + "日出时间:",0));
			
			 _backGround = _loader.uiManager.generateBmp(_loader.uiManager.weatherBack,true);
//			_backGround = new Scale9Grid(bmp.bitmapData,10,10);
			_backGround.width = _stage.stageWidth * 0.9;
			_backGround.height = _risesTitleTxt.height * 1.4;
			_backGround.x = _stage.stageWidth * 0.05;
			
			_risesTxt.mouseEnabled = false;
			_risesTxt.autoSize = "left";
			
			_sunSetTxt.mouseEnabled = false;
			_sunSetTxt.autoSize = "left";
			
			_sunSetTitleTxt.mouseEnabled = false;
			_sunSetTitleTxt.autoSize = "left";
			
			
			TextFieldUtils.setHtmlText(_sunSetTitleTxt,HtmlText.format("日落时间:",0));
			
			_risesTitleTxt.y = (_backGround.height - _risesTitleTxt.height) * 0.5;
			_sunSetTxt.y = _sunSetTitleTxt.y = _risesTxt.y = _risesTitleTxt.y;
			
			_risesTitleTxt.x = _backGround.x + _backGround.width * 0.1;
			_risesTxt.x = _risesTitleTxt.x + _risesTitleTxt.width;
			
			_sunSetTitleTxt.x = _backGround.x + _backGround.width * 0.6;
			_sunSetTxt.x = _sunSetTitleTxt.x + _sunSetTitleTxt.width;
			
			this.addChild(_backGround);
			this.addChild(_risesTitleTxt);
			this.addChild(_risesTxt);
			this.addChild(_sunSetTitleTxt);
			this.addChild(_sunSetTxt);
		}
		
		public function show(info:Object):void
		{
			TextFieldUtils.setHtmlText(_risesTxt,HtmlText.format(info.sunRises,0));
			TextFieldUtils.setHtmlText(_sunSetTxt,HtmlText.format(info.sunSet,0));
		}
		
	}
}